var prefix = getRootPath()+"/${sname}";

$().ready(function() {
	validateRule();
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : prefix+"/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == "SUCCESS") {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	$.validator.setDefaults({
		ignore: ":hidden:not(.chosen-select)"
	});
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			<#list fields as f >
				<#if !f.pk>
				${f.simpleName} : {
                	required : true
                },
				</#if>
			</#list>
		},
		messages : {
           <#list fields as f >
           		<#if !f.pk>
				${f.simpleName} : {
                	required : icon + "请输入${f.name}"
				},
           		</#if>
		   </#list>
		},
		errorPlacement: function (error, element) {
			if (element.is("select")) {
				error.appendTo(element.parent());
			} else {
				error.insertAfter(element);
			}
		},
		submitHandler : function() {
			save();
		}
	})
}